package com.hmall.api.fallBack;

import com.hmall.api.item.ItemClient;
import com.hmall.api.dto.ItemDTO;
import com.hmall.api.dto.OrderDetailDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.Collection;
import java.util.Collections;
import java.util.List;

/**
 * Feign远程调用降级策略
 *
 * @Author mr.lcc
 * @Data 2025/6/18 10:38
 */
@Component
@Slf4j
public class ItemClientFallbackFactory implements FallbackFactory<ItemClient> {
    @Override
    public ItemClient create(Throwable cause) {
        return new ItemClient() {

            /**
             * 根据id批量查询商品
             * @param ids
             * @return
             */
            @Override
            public List<ItemDTO> queryItemByIds(Collection<Long> ids) {
                log.error("Feign远程调用#queryItemByIds失败,参数{}，异常：", ids, cause);
                return Collections.emptyList();
            }

            /**
             * 支付相关接口
             * @param items
             */
            @Override
            public void deductStock(List<OrderDetailDTO> items) {
                log.error("Feign远程调用#deductStock失败,异常：", cause);
            }
        };
    }
}
